package com.recharge.web.controller;

import com.recharge.common.result.ResultDO;
import com.recharge.common.result.web.ObjectResponse;
import com.recharge.domain.query.ReportOrderGoodsStatisQueryDO;
import com.recharge.domain.query.ReportProviderStatisQueryDO;
import com.recharge.service.ReportProviderStatisService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/reportProvider")
public class ReportProviderStatisController extends BaseController {

    @Autowired
    private ReportProviderStatisService reportProviderService;

    @RequiresPermissions("reportProvider:get")
    @RequestMapping(value="/get.html", method = RequestMethod.POST)
    @ApiOperation(value="查询统计供货单商品详情", notes="")
    public @ResponseBody
    ObjectResponse<Object> get(@RequestBody ReportProviderStatisQueryDO param) {
        ObjectResponse<Object> response = new ObjectResponse<>();
        ResultDO result = reportProviderService.get(param.getId());
        if(result.isSuccess()) {
            response.setData(result.getModel(ResultDO.FIRST_MODEL_KEY));
            System.out.println(result.getModel(ResultDO.SECOND_MODEL_KEY));
        } else {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }

    @RequiresPermissions("reportProvider:reportOrder")
    @RequestMapping(value="/reportOrder.html", method = RequestMethod.POST)
    @ApiOperation(value="查询统计", notes="")
    public @ResponseBody
    ObjectResponse<Object> reportOrder(@RequestBody ReportProviderStatisQueryDO query) {
        ObjectResponse<Object> response = new ObjectResponse<>();
        ResultDO result = reportProviderService.reportOrder(query);
        if(result.isSuccess()) {
            response.setData(result.getModel(ResultDO.FIRST_MODEL_KEY));
        } else {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }

    @RequiresPermissions("reportProvider:reportOrderByDayDate")
    @RequestMapping(value="/reportOrderByDayDate.html", method = RequestMethod.POST)
    @ApiOperation(value="查询统计时间维度", notes="")
    public @ResponseBody
    ObjectResponse<Object> reportOrderByDayDate(@RequestBody ReportProviderStatisQueryDO query) {
        ObjectResponse<Object> response = new ObjectResponse<>();
        ResultDO result = reportProviderService.reportOrderByDayDate(query);
        if(result.isSuccess()) {
            response.setData(result.getModel(ResultDO.FIRST_MODEL_KEY));
        } else {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }

    @RequestMapping(value="/taskReport.html", method = RequestMethod.POST)
    @ApiOperation(value="查询统计", notes="")
    public @ResponseBody
    ObjectResponse<Object> taskReport(@RequestBody ReportProviderStatisQueryDO query) {
        ObjectResponse<Object> response = new ObjectResponse<>();
        ResultDO result = reportProviderService.taskReport();
        if(result.isSuccess()) {
            response.setData(result.getModel(ResultDO.FIRST_MODEL_KEY));
        } else {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
}
